package dk.ucn.datamatiker.henrik.bundtkage.earthcake.albeheweather;

import java.io.IOException;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class Weather {

	private String location;
	private String description;
	private String temperature;
	private String temperatureUnit;
	private String windDirection;
	private String windSpeed;
	private String windSpeedUnit;
	private String iconUrl;
	
	public Weather(XmlPullParser parser) throws XmlPullParserException, IOException {
		readWeatherData(parser);
	}
	
	public Weather(){
		
	}
	
	public void readWeatherData(XmlPullParser parser) throws XmlPullParserException, IOException {
		parser.require(XmlPullParser.START_TAG, null, "WeatherData");
		while(parser.next() != XmlPullParser.END_TAG){
			if(parser.getEventType() != XmlPullParser.START_TAG){
				continue;
			}
			
			String name = parser.getName();
			
			if(parser.next() == XmlPullParser.TEXT){
				if(name.equals("Location")){
					setLocation(parser.getText());
					parser.nextTag();
				} else if (name.equals("Description")) {
					setDescription(parser.getText());
					parser.nextTag();
				} else if (name.equals("Temperature")) {
					setTemperature(parser.getText());
					parser.nextTag();
				} else if (name.equals("TemperatureUnit")) {
					setTemperatureUnit(parser.getText());
					parser.nextTag();
				} else if (name.equals("WindDirection")) {
					setWindDirection(parser.getText());
					parser.nextTag();
				} else if (name.equals("WindSpeed")) {
					setWindSpeed(parser.getText());
					parser.nextTag();
				} else if (name.equals("WindSpeedUnit")) {
					setWindSpeedUnit(parser.getText());
					parser.nextTag();
				} else if (name.equals("IconUrl")) {
					setIconUrl(parser.getText());
					parser.nextTag();
				} else {
					parser.nextTag();
				}
			}
		}
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getTemperature() {
		return temperature;
	}

	public void setTemperature(String temperature) {
		this.temperature = temperature;
	}

	public String getTemperatureUnit() {
		return temperatureUnit;
	}

	public void setTemperatureUnit(String temperatureUnit) {
		this.temperatureUnit = temperatureUnit;
	}

	public String getWindDirection() {
		return windDirection;
	}

	public void setWindDirection(String windDirection) {
		this.windDirection = windDirection;
	}

	public String getWindSpeed() {
		return windSpeed;
	}

	public void setWindSpeed(String windSpeed) {
		this.windSpeed = windSpeed;
	}

	public String getWindSpeedUnit() {
		return windSpeedUnit;
	}

	public void setWindSpeedUnit(String windSpeedUnit) {
		this.windSpeedUnit = windSpeedUnit;
	}

	public String getIconUrl() {
		return iconUrl;
	}

	public void setIconUrl(String iconUrl) {
		this.iconUrl = iconUrl;
	}
	
	
}
